package  
{
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;

	import org.xiph.vorbis.VorbisSound;

	/**
	 * Quick test application
	 *
	 * @author Andre Michelle
	 */
	public final class SandboxVorbisDecoding extends Sprite
	{
		private const vorbis: VorbisSound = new VorbisSound();

		public function SandboxVorbisDecoding()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.frameRate = 999.9;

			vorbis.addEventListener( Event.INIT, init );
			vorbis.addEventListener( Event.COMPLETE, complete );
			vorbis.addEventListener( Event.SOUND_COMPLETE, soundComplete );
			vorbis.addEventListener( ProgressEvent.PROGRESS, progress );

			// TEST FILE ON SERVER
			vorbis.load( new URLRequest( 'http://files.andre-michelle.com/vorbis.loop.162831.ogg' ) );
			vorbis.loop = true;
			vorbis.play();
		}

		//----------------------//
		//-- EVENTS BY VORBIS --//
		//----------------------//

		//-- VORBIS HEADER PARSED > INFO AVAILABLE
		private function init( event:Event ):void
		{
			trace( event );

			trace( '<<< VORBIS INFO >>>' );
			trace( vorbis.info.debug() );
			trace( 'loaded', vorbis.loaded );
			trace( 'duration', vorbis.duration );
			trace( '<<< ----------- >>>' );
		}

		//-- COUPLE OF BYTES ARRIVED > EVENTUALLY EXTEND DURATION
		private function progress( event:ProgressEvent ):void
		{
//			trace( event );
		}

		//-- VORBIS FULLY LOADED
		private function complete( event:Event ):void
		{
			trace( event );

//			vorbis.play();
		}

		//-- VORBIS PLAYED ONCE
		private function soundComplete( event:Event ):void
		{
			trace( event );
		}
	}
}